package top.tttfu.util;

import java.sql.*;

public class JDBC {
    //获取数据库链接
    public static Connection getConnection() {
        Connection con = null;
        try {
            String url = "jdbc:mysql://tttfu.top:3306/Todo?serverTimezone=Asia/Shanghai&autoReconnect=true";
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection(url, "tf", "050600");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return con;
    }
    //关闭资源
    public static void close(Connection con, Statement st, ResultSet rs) {
        try {
            if (rs != null) {
                rs.close();
            }
            if (st != null) {
                st.close();
            }
            if (con != null) {
                con.close();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

